package lab02.test06;

public class Triangle {
    Double size1;
    Double size2;
    Double size3;
    Boolean isTriangle;
    public Triangle(double size1,double size2,double size3){
        this.size1=size1;
        this.size2=size2;
        this.size3=size3;
        isTriangle=triangle();
    }
    boolean triangle(){
        if ((size1+size2>size3)&&
                (size1+size3>size2)&&
                (size2+size3>size1)&&
                (size1-size2<size3)&&
                (size1-size3<size2)&&
                (size2-size3<size1))
            return true;
        return false;
    }
    public Double getSize1(){

        return size1;
    }
    public void setSize1(double size1){

        this.size1=size1;
    }
    public Double getSize2(){
        return size2;
    }
    public void setSize2(double size2){

        this.size2=size2;
    }
    public Double getSize3(){

        return size3;
    }
    public void setSize3(double size3){
        this.size3=size3;
    }
    public boolean isTriangle(){
        return isTriangle;
    }
    public void setTriangle(boolean isTriangle){
        this.isTriangle=isTriangle;
    }
    public double getArea(){
        if (isTriangle)

        {
            double c=getPermie()/2;
            return Math.sqrt(c*(c-size1)*(c-size2)*(c-size3));
        }
        throw new IllegalArgumentException("三边不能构成上三角行！");
    }

    public double getPermie() {
        if(isTriangle)
            return size1+size2+size3;
        throw new IllegalArgumentException("三边不能构成上三角行！");
    }

    public static void main(String[] args)
    {
        Triangle triangle=new Triangle(3, 4, 5);
        System.out.println("周长："+triangle.getPermie());
        System.out.println("面积："+triangle.getArea());

        triangle.setSize1(3);
        triangle.setSize2(3);
        triangle.setSize3(3);
        System.out.println("周长："+triangle.getPermie());
        System.out.println("面积："+triangle.getArea());

    }

}
